//
//  EeMsgType.swift
//  message
//
//  Created by zhuxietong on 2016/12/19.
//  Copyright © 2016年 zhuxietong. All rights reserved.
//

import Foundation
import UIKit



extension EeMsgType{
    public var unReadCount:Int{
        get{
            return EeNum.num(self)
        }
    }
    
    public func readAll() {
        EeNum.readAll(type: self)
    }
    
    public func readOne(ID:String) {
        EeNum.delete(ID, type: self)
    }
    
    public func new(ID:String) {
        EeNum.new_item(ID, type: self)
    }
    
    public func isRead(ID:String) ->Bool{
        return EeNum.read_state(ID, type: self)
    }
}

public protocol EeMsgTypeProtocol {
    var rawValue:String{get}
    var NoticeName :String{get}
    var Notice:NSNotification.Name{get}
}




extension String
{
    public var msgType:EeMsgType{
        return EeMsgType(rawValue: "\(self)")
    }
}

open class EeMsgType:EeMsgTypeProtocol{
    
    private var __rawValue = ""
    public init(rawValue:String) {
        self.__rawValue = rawValue
    }
    public var rawValue:String{
        get{
            return self.__rawValue
        }
    }
    
    public var NoticeName :String{return "EeMsgType.\(self.rawValue)"}
    public var Notice:NSNotification.Name{return NSNotification.Name(rawValue: "EeMsgType.\(self.rawValue)")}
    
    public static func appendObserver(types:[EeMsgTypeProtocol]){
        for item in types {
            let value = item.rawValue
            let currentTypes = EeMsgType.types.map { (one) -> String in
                return one.rawValue
            }
            if !currentTypes.contains(value){
                EeMsgType.types.append(item)
            }
        }
    }
    
    public static var types:[EeMsgTypeProtocol] = [EeMsgTypeProtocol]()
    
}

public protocol EeMsgTypeModule {
    var msg:EeMsgType{get}
    static var types:[EeMsgTypeProtocol]{get}
}

